<template>
  <j-modal
    :title='title'
    :width='800'
    :visible='visible'
    :maskClosable='false'
    :ok-button-props='{ props: { disabled: disableSubmit } }'
    :fullscreen='true'
    ok-text='提交审批'
    @close='close'
    cancelText='关闭'>
    <template slot="footer">
      <a-button key="back" style='padding-left:20px;padding-right:20px' @click='close()'>
        关闭
      </a-button>
      <a-popconfirm title='确定不通过吗?' style='width:150px' @confirm="() => setApproveReason('2')">
        <a-button key="save" style='padding-left:8px;padding-right:8px'>
          不通过
        </a-button>
      </a-popconfirm>
      <a-popconfirm title='确定通过吗?' style='width:150px' @confirm="() => setApproveReason('1')">
        <a-button key="submit" type="primary">
          通过
        </a-button>
      </a-popconfirm>
    </template>
    <div style='margin:0 auto;' :class='{isCheck:isCheck}'>
      <table class='table table-striped table-bordered' align='center' valign='center'>
        <tr>
          <td class='column title' colspan='12'>基本信息</td>
        </tr>
        <tr>
          <td class='column'>计划编号</td>
          <td class='value'>
            <a-input v-model='model.number' :disabled='true'></a-input>
          </td>
          <td class='column'>计划年度</td>
          <td class='value'>
            <a-date-picker
              mode='year'
              placeholder='请选择年份'
              format='YYYY'
              value-format='yyyy-MM-dd'
              v-model='model.planYear'
              :open='yearPickShow'
              :disabled='disableSubmit'
              style='width: 100%' />
          </td>
          <td class='column'>计划名称</td>
          <td class='value'>
            <a-input v-model='model.name' :disabled='disableSubmit'></a-input>
          </td>
          <td class='column'>计划负责人</td>
          <td class='value'>
            <a-input v-model='model.principalText' :disabled='true'></a-input>
          </td>
        </tr>
        <tr>
          <td class='column'>审计单位</td>
          <td class='value' colspan='7'>
            <a-input v-if='organShow'
                     v-model='model.remidText'
                     :disabled='true'></a-input>
          </td>
        </tr>
        <tr>
          <td class='column' colspan='1'>年度审计工作目标</td>
          <td class='value' colspan='7'>
            <a-input v-model='model.aims' :disabled='disableSubmit'></a-input>
          </td>
        </tr>
        <tr>
          <td class='column' colspan='12'>审计项目计划明细</td>
        </tr>
        <tr>
          <td class='value' colspan='12' style='padding:0;'>
            <a-table
              class='edit-list'
              size='middle'
              bordered
              :columns='columns1'
              :dataSource='dataSource1'
              :pagination='ipagination1'
              :scroll='{ x: 200, y: 240 }'>
              <span slot='action' slot-scope='text, record'>
                <a @click="handleCheck(record,'年度审计计划制定-查看')">查看</a>
              </span>
            </a-table>
          </td>
        </tr>
        <tr>
          <td class='column' colspan='12'>调整</td>
        </tr>
        <tr>
          <td class='value' colspan='12' style='padding:0;'>
            <a-table
              class='edit-list'
              size='middle'
              bordered
              :columns='columns2'
              :dataSource='dataSource2'
              :pagination='ipagination2'
              :scroll='{ x: 200, y: 240 }'>
              <span slot='action' slot-scope='text, record'>
                <a @click="handleCheck( record,'年度审计计划制定-查看')">查看</a>
              </span>
            </a-table>
          </td>
        </tr>
        <tr>
          <td class='column' colspan='12'>审核记录</td>
        </tr>
        <tr>
          <td class='value' colspan='12' style='padding:0;'>
            <a-table
              class='edit-list'
              size='middle'
              bordered
              :columns='columns3'
              :dataSource='dataSource3'
              :pagination='ipagination3'
              :scroll='{ x: 200, y: 240 }'>
            </a-table>
          </td>
        </tr>
      </table>
    </div>
    <!-- table区域-end -->

    <SetReason ref='setReason' @approveData='approveReport'></SetReason>
    <PlanDetails ref='modalForm'></PlanDetails>
  </j-modal>
</template>
<script>
import { httpAction, getAction, postAction } from '@/api/manage'
import columns1 from './columns1'
import columns2 from './columns2'
import columns3 from './columns3'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import SetReason from "./SetReason"
import PlanDetails from '../ndsjjhzd/PlanDetails'
export default {
  name: 'SysPositionModal',
  mixins: [JeecgListMixin],
  components: {
    SetReason,
    PlanDetails
  },
  data() {
    return {
      proId:null,
      disableSubmit: false,
      title: '机构信息',
      visible: false,
      isCheck: false,
      url: {
        get: '/sjzyzhgl/sjPlanInfo/planInfoList',
        list: '/sjzyzhgl/sjPlanProjectInfo/projectInfoByProId',
        approveList: '/sjzyzhgl/sjApplyLog/queryApplyLogListByPId',//审批记录列表
        passApply:'/common/sjProcCommon/planGuo',
        banApply:'/common/sjProcCommon/planDown'
      },
      organShow: true,
      model: {
        remidText: '',
        remid: ''
      },
      approveType:'1',
      yearPickShow: false,
      columns1: columns1(this),
      columns2: columns2(this),
      columns3: columns3(this),
      dataSource1: [],
      dataSource2: [],
      dataSource3: [],
      ipagination1: {
        current: 1,
        pageSize: 10,
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        onChange: (pageNumber) => {
          this.onChange1(pageNumber)
        },
        showQuickJumper: true,
        total: 0
      },
      ipagination2: {
        current: 1,
        pageSize: 10,
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        onChange: (pageNumber) => {
          this.onChange2(pageNumber)
        },
        showQuickJumper: true,
        total: 0
      },
      ipagination3: {
        current: 1,
        pageSize: 10,
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        onChange: (pageNumber) => {
          this.onChange3(pageNumber)
        },
        showQuickJumper: true,
        total: 0
      },
    }
  },
  created() {
  },
  methods: {
    approve(record) {
      this.model = Object.assign({}, record)
      this.proId = this.model.id
      this.visible = true
      this.httpRequest()
      this.list1()
      this.list2()
      this.list3()
    },
    // 获取计划信息
    httpRequest() {
      getAction(this.url.get, { id: this.model.id }).then((res) => {
        if (res.success && res.result) {
          this.model = res.result.records[0]
        } else {
          console.log(res)
        }
      }).finally(() => {
      })
    },
    list1() {
      getAction(this.url.list, {
        proId: this.proId,
        pageSize: this.ipagination1.pageSize,
        pageNo: this.ipagination1.current,
        operationFlag:'normal'
      }).then((res) => {
        if (res.success && res.result) {
          this.dataSource1 = res.result.records
          this.ipagination1.total = res.result.total
        } else {
          this.ipagination1.total = 0
        }
      })
    },
    list2() {
      getAction(this.url.list, {
        proId: this.proId,
        pageSize: this.ipagination1.pageSize,
        pageNo: this.ipagination1.current,
        operationFlag:'adjust'
      }).then((res) => {
        if (res.success && res.result) {
          this.dataSource2 = res.result.records
          this.ipagination2.total = res.result.total
        } else {
          this.ipagination2.total = 0
        }
      })
    },
    list3() {
      getAction(this.url.approveList, {
        pid: this.proId,
        pageSize: this.ipagination3.pageSize,
        pageNo: this.ipagination3.current,
      }).then((res) => {
        if (res.success && res.result) {
          this.dataSource3 = res.result.records
          this.ipagination3.total = res.result.total
        } else {
          this.ipagination3.total = 0
        }
      })
    },
    // 点击关闭或提交审核
    close() {
      this.visible = false
    },
    setApproveReason(param){
      this.approveType = param
      this.$refs.setReason.setApproveReason = true
    },
    // 审批
    approveReport(param){
      let httpurl
      if(this.approveType == '1'){
        httpurl = this.url.passApply
      }else{
        httpurl = this.url.banApply
      }
      getAction(httpurl, {
        proId: this.proId,
        reason: param
      }).then((res) => {
        if (res.success && res.result) {
          this.$message.success(res.result);
          this.$emit('ok')
          this.visible = false
        } else {

        }
      })
    },
    // 分页
    onChange1(pageNumber) {
      this.ipagination1.current = pageNumber
      this.list1()
    },
    onChange2(pageNumber) {
      this.ipagination2.current = pageNumber
      this.list2()
    },
    onChange3(pageNumber) {
      this.ipagination3.current = pageNumber
      this.list3()
    },
  }
}
</script>

<style lang='less' scoped>
@import '../../css/checkAndEdit.less';
/deep/ .ant-table-hide-scrollbar {
  scrollbar-color: unset !important;
  margin-bottom: -10px !important;
}
</style>
